package com.museum.main;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.museum.entities.base.Item;
import com.museum.entities.market.MarketList;
import com.museum.utils.Sentor;

public class ItemList {
	private static Sentor s = new Sentor();
	private static Map<Integer, Item> itemMap = new HashMap<Integer, Item>();

	public static void main(String[] args) {
		int total = 1;
		for (int i = 1; i <= Math.ceil(total / 8.0); i++) {
			System.out.println("the " + i + " page");
			MarketList ml = null;
			try {
				ml = s.marketList(0, i);
			} catch (Exception e) {
			}
			if (ml != null) {
				total = ml.getData().getTotal();
				List<Item> pl = ml.getData().getList();
				for (Iterator<Item> it = pl.iterator(); it.hasNext();) {
					Item item = it.next();
					int itemid = item.getItem_id();
					if (!itemMap.containsKey(itemid)) {
						itemMap.put(itemid, item);
					}
				}
			}
		}
		for (Iterator<Integer> it = itemMap.keySet().iterator(); it.hasNext();) {
			Item item = itemMap.get(it.next());
			if (item.getBuy_price() < item.getSell_price())
				System.out.println(item.getItem_id() + "\t"
						+ item.getItem_name() + "\t"
						+ (item.getSell_price() - item.getBuy_price()));
		}
	}

}
